
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>新增记录</title>
  <link rel="stylesheet" href="../../css/element.css">
	<link rel="stylesheet" href="../../css/common.css">
  <link rel="stylesheet" href="../../css/edit.css"> 
    
</head>

<body>
	<div id="app" v-cloak>
        <div id="mask" v-if="maskShow"></div>
        <div id="notice-mask" v-if="ifNoticeListShow">
          <div id="notice-wrap">
            <p class="item-title">选择公告原文</p>
            <el-table
              ref="singleTable"
              :data="noticeResult"
              stripe
              highlight-current-row
              @current-change="selectNotice"
              style="width: 100%"
              >
              
              
              <el-table-column
                width="1000"
                label="扣分内容">
                <template slot-scope="scope">
                  <a :href="scope.row.deal_content_url" class="table-link" target="blank">{{ scope.row.deal_content }}</a>
                </template>
              </el-table-column>
              <el-table-column
                prop="deal_time"
                label="日期">
              </el-table-column>
            </el-table>

            <p style="text-align: center;">
              <el-button type="primary" @click="ifNoticeListShow=false;preventUploadFile=true;preventSelFile=false">确定</el-button>
            </p>
          </div>
        </div>
        <el-container style="height: 100%;">


          <el-header>
            <div class="layout-logo">
                <img src="../../images/logo.png" alt="">
            </div>
            <!-- <div class="head-nav">
              <a href="javascript:void(0)" class="active">合规审核</a>
              <a href="../dataquery/complex.html">数据查询</a>
            </div> -->
            <div class="layout-nav font12 user_msg">
                欢迎您，{{userName}}  <a class="red" href="javascript:void(0)" @click="userQuit"> 注销 </a>
            </div>
          </el-header>

          <el-container>
           
            <!-- 右侧主视图部分 BEGIN  -->
            <el-container>

              <!-- content container begin -->
              <el-main>
                <el-card class="main-card">
  
                  <div slot="header" class="clearfix">
                    <span class="font12 gray">当前位置：新增记录</span>
                  </div>

                  <div class="clearfix main-wrap" style="height:100%;">
                    <div class="fl" style="width:50%;height:100%;">
                      
                      <p class="item-title">新增记录</p>

                      <div class="item-wrap">
                        <span class="input-label">
                          <dd>证券代码：</dd>
                          <el-select v-model="selectedStock" filterable placeholder="请选择" size="small">
                            <el-option
                              v-for="item in allStocks"
                              :key="item[1]"
                              :label="item[0]"
                              :value="item[0]">
                            </el-option>
                          </el-select>
                        </span>
                      </div>
                      <div class="item-wrap col-2">
                        
                        <span class="input-label">
                          <dd>扣分类型：</dd>
                          <el-select size="small" v-model="formVal.deal_type">
                            <el-option v-for="item in deTypeArr" :label="item" :value="item"></el-option>
                          </el-select>
                        </span>

                        <span class="input-label">
                          <dd>扣分内容：</dd>
                          <el-input size="small" v-model="formVal.deal_content"></el-input>
                        </span>
                      </div>


                      <div class="item-wrap">
                        <span class="input-label">
                          <dd>扣分值：</dd>
                          <el-input size="small" max=0 min=-100 type="number" v-model="formVal.deal_score"></el-input>
                        </span>
                      </div>

                      <div class="item-wrap">
                        <span class="input-label">
                          <dd>选择状态：</dd>
                          <el-input size="small" v-model="formVal.audit_state" disabled></el-input>
                        </span>
                      </div>

                      <div class="item-wrap col-2">
                        <span class="input-label">
                          <dd class="long">选择公告原文：</dd>
                          <el-button size="small" @click="chooseNotice" type="primary" :disabled='preventSelFile'>选择公告</el-button>
                        </span>

                        <span class="input-label">
                          <dd>上传公告：</dd>
                          <!-- <el-upload
                            class="uploadWrap"
                            action="https://goldeye.cfbond.com/cmsys/upload"
                            :auto-upload="true"
                            :before-upload="beforeUpload"
                            :on-success="upLoadSuccess"
                            :on-error="upLoadFailed"
                            >
                            <el-button size="small" type="primary">上传公告文件</el-button>
                          </el-upload> -->
                          <form id="uploadForm">
                             <a href="javascript:;" class="a-upload" :class="{'unClick':preventUploadFile}">
                                <input type="file" name="file" id="fileObj" v-on:change="getFileName" v-if="!preventUploadFile">选择文件
                            </a> 
                            <span class="fileName">{{fileName}}</span>
                          </form>
                        </span>
                      </div>

                      <div class="item-wrap col-2">
                        <span class="input-label">
                          <dd class="long">公告日期：</dd>
                          <el-date-picker v-model="formVal.deal_time" type="date" placeholder="选择日期" size="small" value-format="yyyy-MM-dd"></el-date-picker>
                        </span>

                        <span class="input-label">
                          <dd>标题：</dd>
                          <el-input size="small" v-model="formVal.deal_title" style="width:300px"></el-input>
                        </span>
                      </div>

                      <div class="item-wrap">

                        <span class="input-label">
                          <dd>备注：</dd>
                          <el-input size="small"  type="textarea" v-model="formVal.note"></el-input>
                        </span>
                      </div>

                      <div class="item-wrap bottom-button">
                        <el-button type="primary" @click="submitForm">确定</el-button>
                        <el-button type="info" @click="cancelForm">取消</el-button>
                      </div>
                    </div>

                    <div class="fl" style="width:50%;height:100%;">
                      <p class="query-title">
                        请输入要查询的公司代码:
                        <el-input size="small" v-model="querySecuCode"></el-input>
                        <el-button size="small" type="primary" @click="getQuery(querySecuCode)">查询</el-button>
                      </p>

                      <div class="table-wrap">
                        <el-table
                        :data="queryResult"
                        v-loading="loading"
                        border
                        stripe
                        style="width: 100%"
                        empty-text="该公司暂无扣分项"
                        >
                        
                        <el-table-column
                          prop="deal_time"
                          label="日期">
                        </el-table-column>
                        <el-table-column
                          prop="deal_type"
                          label="扣分类型">
                        </el-table-column>
                        <el-table-column
                          label="扣分内容">
                          <template slot-scope="scope">
                            <a :href="scope.row.deal_content_url" class="table-link" target="blank">{{ scope.row.deal_content }}</a>
                          </template>
                        </el-table-column>
                        <el-table-column
                          prop="deal_score"
                          label="扣分值">
                        </el-table-column>

                      </el-table>
                      </div>
                    </div>
                  </div>
  
                </el-card>
              </el-main>
              <!-- content container end -->


              <el-footer>
                  <p class="gray">
                    @中国财富传媒集团 版权所有
                  </p>
              </el-footer>

            </el-container>
            <!-- 右侧主视图部分 END  -->
          </el-container>

        </el-container>
    </div>
</body>
    <script src="../../js/jquery3.3.1.min.js"></script>
    <script src="../../js/vue.js"></script>
    <script src="../../js/element.js"></script>
    <script src="../../js/axios.min.js"></script>
    <script src="../../js/common.js"></script>
  	<script>
  	  var app = new Vue({
  	      el: '#app',
          data(){
            return{
              selectedStock:'',
              maskShow:false,
              userName:localStorage.sys_userName,
              deTypeArr:[],
              querySecuCode:'',
              int_date:'',
              loading:false,
              ifNoticeListShow:false,
              queryResult:[],
              noticeResult:[],
              ifAvailable:false,
              fileTest:'',
              fileName:'暂未选取文件',
              preventSelFile:false,
              preventUploadFile:false,
              allStocks:[],
              formVal:{
                login_name:localStorage.sys_userName,
                secu_code:'',
                company_name:'',
                deal_type:'',
                deal_content:'',
                deal_score:0,
                audit_state:'新增',
                deal_time:'',
                deal_title:'',
                deal_url:'',
                note:''
                
              }
            }
              
          },
          mounted:function(){
              this.initPage();
          },
          watch: {
            selectedStock: function () {
                this.formVal.company_name = this.selectedStock.split('(')[0]
                this.formVal.secu_code = this.selectedStock.split('(')[1].slice(0,6);
                console.log(this.formVal);
            }
          },
          methods:{
            userQuit:function(){
              this.$confirm('确认退出当前账户？', '确认退出', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(()=>{
                    Common.quit();
              }).catch(()=>{
                return false;
              });


            },
            initPage:function(){

              // 获取扣分类型
              axios
              .get(`https://goldeye.cfbond.com/cmsys/deal_type?session_id=${localStorage.sys_sessionId}`)
              .then((res)=>{
                if(res.data.flag){
                  this.deTypeArr = res.data.data;
                  this.deTypeSel = this.deTypeArr[0];
                }else{

                }
                
              }); 

              // 获取所有证券列表
              axios
              .get(`https://goldeye.cfbond.com/cattle/all_company_info?session_id=${localStorage.sys_sessionId}`)
              .then((res)=>{
                if(res.data.flag){
                  this.allStocks = res.data.data;
                }
              })             
            },
            getQuery:function(sCode){
              if(sCode.length!=6){
                this.$message.error('错误的证券代码');
              }else{
                this.loading = true;
                axios
                .get(`https://goldeye.cfbond.com/cmsys/compliance_audit_list?session_id=${localStorage.sys_sessionId}`,{
                  params:{
                    secu_code:sCode,
                    page_size:1000,
                    audit_state:'全部',
                    api_type:'add'
                  }
                })
                .then((res)=>{
                  if(res.data.flag){
                    this.queryResult = res.data.data.data_list;
                  }
                  this.loading = false;
                });
              }
              
            },
            chooseNotice:function(){
              if(this.formVal.secu_code.length!=6){
                this.$message.error('请先输入正确的证券代码！');
              }else{
                axios
                .get(`https://goldeye.cfbond.com/cmsys/compliance_audit_list?session_id=${localStorage.sys_sessionId}`,{
                  params:{
                    secu_code:this.formVal.secu_code,
                    page_size:1000,
                    audit_state:'全部'
                  }
                })
                .then((res)=>{
                  if(res.data.flag){
                    this.noticeResult = res.data.data.data_list;
                    this.ifNoticeListShow = true;
                  }
                });
              }
            },
            selectNotice:function(val){
              if(val){
                this.formVal.deal_time = val.deal_time;
                this.formVal.deal_title= val.deal_content;
                this.formVal.deal_url= val.deal_content_url;
                this.ifAvailable = true;
                // this.ifNoticeListShow = false;
              }else{}
            },
            submitForm:function(){
              let _this = this;
              var formData = new FormData(document.getElementById('uploadForm'));
              console.log(formData);
              // axios({
              //  url:'https://goldeye.cfbond.com/cmsys/upload',
              //  method:'post',
              //  headers:{
              //    'Content-Type': 'application/json;charset=UTF-8'
              //  }
              //  params:formData
              // })
              if(!this.preventUploadFile&&this.preventSelFile){//文件为上传型
                $.ajax({
                  url:'https://goldeye.cfbond.com/cmsys/upload',
                  type:'POST',
                  data:formData,
                  contentType:false,
                  processData:false,
                  success:function(res){
                   
                    _this.formVal.deal_url = res.url;
                    _this.preventSelFile = true;
                    if(_this.formVal.secu_code==''||_this.formVal.company_name==''||_this.formVal.deal_type==''||_this.formVal.deal_content==''||_this.formVal.audit_state==''||_this.formVal.deal_time==''){
                      _this.$message.error('除备注、公告，其余每项均为必填项，请以上完善信息');
                    }else{
                      console.log(_this.formVal);
                      axios
                      .get(`https://goldeye.cfbond.com/cmsys/compliance_audit_add?session_id=${localStorage.sys_sessionId}`,{
                        params:_this.formVal
                      })
                      .then((res)=>{
                        if(res.data.flag){
                          _this.$alert('添加成功', '成功', {
                            confirmButtonText: '确定',
                            callback: action => {
                              window.location.href="./audit.html";
                            }
                          });
                        }
                      });
                    }
                  },
                  error:function(res){
                    console.log(res);
                  }
                })
              }else{
                if(this.formVal.secu_code==''||this.formVal.company_name==''||this.formVal.deal_type==''||this.formVal.deal_content==''||this.formVal.audit_state==''||this.formVal.company_name==''||_this.formVal.deal_time==''){
                      this.$message.error('除备注、公告外，其余每项均为必填项，请以上完善信息');
                }else{
                   axios
                   .get(`https://goldeye.cfbond.com/cmsys/compliance_audit_add?session_id=${localStorage.sys_sessionId}`,{
                     params:this.formVal
                   })
                   .then((res)=>{
                     if(res.data.flag){
                       this.$alert('添加成功', '成功', {
                         confirmButtonText: '确定',
                         callback: action => {
                           window.location.href="./audit.html";
                         }
                       });
                     }
                   });
                }
              }
              
              
            },
            cancelForm:function(){
              this.$confirm('确定退出编辑，返回列表页?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
                window.location.href="./audit.html";
              }).catch(() => {
                        
              });
            },
            uploadFormFn:function(){
              
            },
            getFileName:function(){
              this.preventUploadFile=false;
              this.preventSelFile=true;
              var arrs=$('#fileObj').val().split('\\');
              var filename=arrs[arrs.length-1];
              this.fileName = filename;
            }

          }
  	  });
  	</script>

</html>